package com.lqq.sparrow.util;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author liangqq
 */
@Slf4j
public abstract class ProxyUtil {

    public static <T> T getBean(Class<T> clazz){

        Object instance = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                new Class[]{clazz}, new InvocationHandler() {
                    //@Override
                    //public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    //    //log.info("代理相关的参数:{}{}{}", proxy, method, args);
                    //    return null;
                    //}

                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                        log.info("代理方法{}已经调用", method);
                        return null;
                    }
                });
        return (T)instance;
    }
}
